package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Reference
    MemberService memberService;

    @RequestMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean pageBean) {
        try {
            return  memberService.findByPage(pageBean);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Member member){
        //todo
        return null;
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Member member){
        //todo
        return null;
    }
    @RequestMapping("/findById")
    public Result findById(@RequestParam("id") int memberId){
        try {
            Member member = memberService.findByid(memberId);
            return new Result(true, MessageConstant.QUERY_MEMBER_SUCCESS,member);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.QUERY_MEMBER_FAIL);
        }
    }
}
